﻿//户内通用下拉框的获取
var uri = document.location.search;//接收页面传值
var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
var P_ReportNumber = uri.substr(i);//截取问号前面的值
$(function () {

    ///判断状态去取消按钮
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/selectbyP_ReportNumberss",
        data: {
            P_ReportNumber: P_ReportNumber
        },
        async: false,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    if (data.T_State != 1) {
                        $("#jbSub").remove();
                    }
                }
            }
        }
    })

    $.ajax({
        type: "get",
        url: ApiUrl + "api/Dictionary/GetDictionaryList",
        data: {
            Dmenuid: [1,23,24,25,26]
        },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                $("option").remove();
                var s = '<option value="" selected=selected>0室</option><option value="1">1室</option><option value="2">2室</option><option value="3>3室</option><option value="4">4室</option><option value="5">5室</option><option value="6">6室</option>"';
                $("#T_SeveralBedroom").append(s)
                var s1 = '<option value="" selected=selected>0厅</option><option value="1">1厅</option><option value="2">2厅</option><option value="3">3厅</option><option value="4">4厅</option><option value="5">5厅</option><option value="6">6厅</option>';
                $("#T_Severaldrawing").append(s1);
                var s2 = '<option value="" selected=selected>0卫</option><option value="1">1卫</option><option value="2">2卫</option><option value="3">3卫</option><option value="4">4卫</option><option value="5">5卫</option><option value="6">6卫</option>';
                $("#T_Severalbathroom").append(s2);
                var s3 = '<option value="" selected=selected>0厨</option><option value="1">1厨</option><option value="2">2厨</option><option value="3">3厨</option><option value="4">4厨</option><option value="5">5厨</option><option value="6">6厨</option>';
                $("#T_SeveralKITCHEN").append(s3);
                var s4 = '<option value="" selected=selected>0阳台</option><option value="1">1阳台</option><option value="2">2阳台</option><option value="3">3阳台</option><option value="4">4阳台</option><option value="5">5阳台</option><option value="6">6阳台</option>';
                $("#T_Severalbalcony").append(s4);
                var s5 = '<option value="" selected=selected>0露台</option><option value="1">1露台</option><option value="2">2露台</option><option value="3">3露台</option><option value="4">4露台</option><option value="5">5露台</option><option value="6">6露台</option>';
                $("#T_SeveralTerrace").append(s5);
                var s6 = '<option value="" selected=selected>0小院</option><option value="1">1小院</option><option value="2">2小院</option><option value="3">3小院</option><option value="4">4小院</option><option value="5">5小院</option><option value="6">6小院</option>';
                $("#T_SeveralSmall").append(s6);
                $(data).each(function (i, obj) {
                    $(obj).each(function (j, item) {
                        switch (item.Dmenuid) {
                            case 1:
                                $("#T_purposeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 25: $("#T_DrawingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 23:
                                $("#T_OrientationID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 24:$("#T_ResidenceID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            //case 25: $("#T_RoomdescribeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            //    break;
                            case 26:
                                $("#T_RoomdescribeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                $("#T_HabitableID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                $("#T_ToiletID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                $("#T_KitchenID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                        }
                    })
                })
            }
        }
    })
})
//户内部分的数据添加
function insertIndoor() {
    var T_purposeID = $("#T_purposeID option:checked").attr("value");      //--房实际用途编号
   // var I_Buildingafew = $("#I_Buildingafew").val();           ///多少栋楼
    var T_Floor = $("#T_Floor").val();                      //--总楼层
    var T_Storey = $("#T_Storey").val();                     //--所在楼层
    var T_OrientationID = $("#T_OrientationID option:checked").attr("value");  //--朝向编号
    var T_ResidenceID = $("#T_ResidenceID option:checked").attr("value");    //--住宅类型编号
    var T_SeveralBedroom = $("#T_SeveralBedroom").val();             // --几个卧室
    var T_Severaldrawing = $("#T_Severaldrawing").val();                // --几个客厅
    var T_Severalbathroom = $("#T_Severalbathroom").val();              // --几个卫生间
    var T_SeveralKITCHEN = $("#T_SeveralKITCHEN").val()              // --几个厨房

    var T_Severalbalcony = $("#T_Severalbalcony").val();                // --几个阳台
    var T_SeveralTerrace = $("#T_SeveralTerrace").val();              // --几个露台
    var T_SeveralSmall = $("#T_SeveralSmall").val()              // --几个小院  
    var T_DrawingID = $("#T_DrawingID option:checked").attr("value");          //有无客厅编号（字典）
    var T_RoomdescribeID = $("#T_RoomdescribeID option:checked").attr("value");//有客厅装修情况描述（字典）
    //内墙
    var T_RoomdescribeInteriorwall = [];
    $("input[name='T_RoomdescribeInteriorwall']").each(function () {
        if (this.checked)
            T_RoomdescribeInteriorwall.push(this.value);
    })
    var T_RoomdescribeInteriorwallOther = $("#T_RoomdescribeInteriorwallOther").val();
    //顶棚
    var T_RoomdescribeCeiling = [];
    $("input[name='T_RoomdescribeCeiling']").each(function () {
        if (this.checked)
            T_RoomdescribeCeiling.push(this.value);
    })
    var T_RoomdescribeCeilingOther = $("#T_RoomdescribeCeilingOther").val();
    //地面
    var T_RoomdescribeGround = [];
    $("input[name='T_RoomdescribeGround']").each(function () {
        if (this.checked)
            T_RoomdescribeGround.push(this.value);
    })
    var T_RoomdescribeGroundOther = $("#T_RoomdescribeGroundOther").val();
    //装修程度
    var T_HabitableID = $("#T_HabitableID option:checked").attr("value");
    //内墙
    var T_HabitableInteriorwall = [];
    $("input[name='T_HabitableInteriorwall']").each(function () {
        if (this.checked)
            T_HabitableInteriorwall.push(this.value);
    })
    var T_HabitableInteriorwallOther = $("#T_HabitableInteriorwallOther").val();
    //顶棚
    var T_HabitableCeiling = [];
    $("input[name='T_HabitableCeiling']").each(function () {
        if (this.checked)
            T_HabitableCeiling.push(this.value);
    })
    var T_HabitableCeilingOther = $("#T_HabitableCeilingOther").val();
    //地面
    var T_HabitableGround = [];
    $("input[name='T_HabitableGround']").each(function () {
        if (this.checked)
            T_HabitableGround.push(this.value);
    })
    var T_HabitableGroundOther = $("#T_HabitableGroundOther").val();
    //卫生的装修情况
    var T_ToiletID = $("#T_ToiletID option:checked").attr("value");
    //卫生间装修情况--内墙
    var T_ToiletInteriorwall = [];
    $("input[name='T_ToiletInteriorwall']").each(function () {
        if (this.checked)
            T_ToiletInteriorwall.push(this.value);
    })
    var T_ToiletInteriorwallOther = $("#T_ToiletInteriorwallOther").val();
    //卫生间装修情况--顶棚
    var T_ToiletCeiling = [];
    $("input[name='T_ToiletCeiling']").each(function () {
        if (this.checked)
            T_ToiletCeiling.push(this.value);
    })
    var T_ToiletCeilingOther = $("#T_ToiletCeilingOther").val();
    //卫生间装修情况--地面
    var T_ToiletGround = [];
    $("input[name='T_ToiletGround']").each(function () {
        if (this.checked)
            T_ToiletGround.push(this.value);
    })
    var T_ToiletGroundOther = $("#T_ToiletGroundOther").val();
    //厨房的装修情况
    var T_KitchenID = $("#T_KitchenID option:checked").attr("value");
    //厨房装修情况--内墙
    var T_KitchenInteriorwall = [];
    $("input[name='T_KitchenInteriorwall']").each(function () {
        if (this.checked)
            T_KitchenInteriorwall.push(this.value);
    })
    var T_KitchenInteriorwallOther = $("#T_KitchenInteriorwallOther").val();
    //厨房装修情况--顶棚
    var T_KitchenCeiling = [];
    $("input[name='T_KitchenCeiling']").each(function () {
        if (this.checked)
            T_KitchenCeiling.push(this.value);
    })
    var T_KitchenCeilingOther = $("#T_KitchenCeilingOther").val();
    //厨房装修情况--地面
    var T_KitchenGround = [];
    $("input[name='T_KitchenGround']").each(function () {
        if (this.checked)
            T_KitchenGround.push(this.value);
    })
    var T_KitchenGroundOther = $("#T_KitchenGroundOther").val();
    //相关说明
    var T_Explain=$("#T_Explain").val();
    var parms = {
        T_purposeID: T_purposeID,             //--房实际用途编号
        T_Floor: T_Floor,                     //--总楼层
        T_Storey: T_Storey,                   //--所在楼层
        T_OrientationID: T_OrientationID,     //--朝向编号
        T_ResidenceID: T_ResidenceID,         //--住宅类型编号
        T_SeveralBedroom: T_SeveralBedroom,   // --几个卧室
        T_Severaldrawing: T_Severaldrawing,   // --几个客厅
        T_Severalbathroom: T_Severalbathroom,  // --几个卫生间
        T_SeveralKITCHEN: T_SeveralKITCHEN,   // --几个厨房
        T_Severalbalcony: T_Severalbalcony,   //几个阳台
        T_SeveralTerrace: T_SeveralTerrace,    //几个露台
        T_SeveralSmall: T_SeveralSmall,           //几个小院

        T_DrawingID: T_DrawingID,                                         //有无客厅编号（字典）
        T_RoomdescribeID: T_RoomdescribeID,                               //有客厅装修情况描述（字典）
        T_RoomdescribeInteriorwall     :T_RoomdescribeInteriorwall.toString(),            //客厅装修选择说明内墙复选框选择值 1,2,3
        T_RoomdescribeInteriorwallOther:T_RoomdescribeInteriorwallOther,  //客厅装修选择说明内墙其它
        T_RoomdescribeCeiling: T_RoomdescribeCeiling.toString(),                      //客厅装修选择说明顶棚复选框选择值 1,2,3
        T_RoomdescribeCeilingOther     :T_RoomdescribeCeilingOther,            //客厅装修选择说明顶棚其它
        T_RoomdescribeGround: T_RoomdescribeGround.toString(),                        //客厅装修选择说明地面复选框选择值 1,2,3
        T_RoomdescribeGroundOther      :T_RoomdescribeGroundOther,              //客厅装修选择说明地面其它
        T_HabitableID                  :T_HabitableID,                                      //居室装修情况编号（字典）
        T_HabitableInteriorwall: T_HabitableInteriorwall.toString(),                  //居室装修选择说明内墙复选框选择值 1,2,3
        T_HabitableInteriorwallOther   :T_HabitableInteriorwallOther,        //居室装修选择说明内墙其它
        T_HabitableCeiling: T_HabitableCeiling.toString(),                            //居室装修选择说明顶棚复选框选择值 1,2,3
        T_HabitableCeilingOther        :T_HabitableCeilingOther,                  //居室装修选择说明顶棚其它
        T_HabitableGround: T_HabitableGround.toString(),                              //居室装修选择说明地面复选框选择值 1,2,3
        T_HabitableGroundOther         :T_HabitableGroundOther,                    //居室装修选择说明地面其它
        T_ToiletID                     :T_ToiletID,                                            //卫生间装修情况编号（字典）
        T_ToiletInteriorwall: T_ToiletInteriorwall.toString(),                        //卫生间装修选择说明内墙复选框选择值 1,2,3
        T_ToiletInteriorwallOther      :T_ToiletInteriorwallOther,              //卫生间装修选择说明内墙其它
        T_ToiletCeiling: T_ToiletCeiling.toString(),                                  //卫生间装修选择说明顶棚复选框选择值 1,2,3
        T_ToiletCeilingOther           :T_ToiletCeilingOther,                        //卫生间装修选择说明顶棚其它
        T_ToiletGround: T_ToiletGround.toString(),                                    //卫生间装修选择说明地面复选框选择值 1,2,3
        T_ToiletGroundOther            :T_ToiletGroundOther,                          //卫生间装修选择说明地面其它
        T_KitchenID                    :T_KitchenID,                                          //厨房装修情况编号 （字典）
        T_KitchenInteriorwall: T_KitchenInteriorwall.toString(),                      //厨房装修选择说明内墙复选框选择值 1,2,3
        T_KitchenInteriorwallOther     :T_KitchenInteriorwallOther,            //厨房装修选择说明内墙其它
        T_KitchenCeiling: T_KitchenCeiling.toString(),                                //厨房装修选择说明顶棚复选框选择值 1,2,3
        T_KitchenCeilingOther          :T_KitchenCeilingOther,                      //厨房装修选择说明顶棚其它
        T_KitchenGround: T_KitchenGround.toString(),                                  //厨房装修选择说明地面复选框选择值 1,2,3
        T_KitchenGroundOther           :T_KitchenGroundOther,                        //厨房装修选择说明地面其它
        T_Explain                      : T_Explain,                                             //	 --有关说明           有关说明
        T_ReportNumber: P_ReportNumber,                                   //报告号
    }
    $.ajax({
        type: "post",
        url: ApiUrl + "api/Indoor/Postinsert",
        data: parms,
        success: function (data, status) {
            if (status == "success") {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }
            }
        }
    })
}
//数据回填
$(function () {
    //根据报告号判断户内部分有没有以前填写的数据如果有回填
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Indoor/SelectByid",
        data: { P_ReportNumber: P_ReportNumber },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    $("#T_purposeID").val(data.T_purposeID);
                    $("#T_Floor").val(data.T_Floor);
                    $("#T_Storey").val(data.T_Storey);
                    $("#T_OrientationID").val(data.T_OrientationID);
                    $("#T_ResidenceID").val(data.T_ResidenceID);
                    $("#T_SeveralBedroom ").val(data.T_SeveralBedroom);
                    $("#T_Severaldrawing ").val(data.T_Severaldrawing);
                    $("#T_Severalbathroom ").val(data.T_Severalbathroom);
                    $("#T_SeveralKITCHEN").val(data.T_SeveralKITCHEN);
                    $("#T_Severalbalcony").val(data.T_Severalbalcony);
                    $("#T_SeveralTerrace ").val(data.T_SeveralTerrace);
                    $("#T_SeveralSmall   ").val(data.T_SeveralSmall);
                    $("#T_DrawingID      ").val(data.T_DrawingID);
                    $("#T_RoomdescribeID ").val(data.T_RoomdescribeID);
                    if (data.T_RoomdescribeInteriorwall != "" && data.T_RoomdescribeInteriorwall != null) {
                        $(data.T_RoomdescribeInteriorwall.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_RoomdescribeInteriorwall']").prop("checked", true);
                        });
                    }
                    $("#T_RoomdescribeInteriorwallOther").val(data.T_RoomdescribeInteriorwallOther); //客厅装修选择说明内墙其它
                    if (data.T_RoomdescribeCeiling != "" && data.T_RoomdescribeCeiling != null) {
                        $(data.T_RoomdescribeCeiling.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_RoomdescribeCeiling']").prop("checked", true);
                        });
                    }
                    $("#T_RoomdescribeCeilingOther").val(data.T_RoomdescribeCeilingOther);      //客厅装修选择说明顶棚其它
                    if (data.T_RoomdescribeGround != "" && data.T_RoomdescribeGround != null) {
                        $(data.T_RoomdescribeGround.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_RoomdescribeGround']").prop("checked", true);
                        });
                    }
                    $("#T_RoomdescribeGroundOther").val(data.T_RoomdescribeGroundOther);       //客厅装修选择说明地面其它
                    $("#T_HabitableID").val(data.T_HabitableID);                   //居室装修情况编号（字典）
                    if (data.T_HabitableInteriorwall != "" && data.T_HabitableInteriorwall != null) {
                        $(data.T_HabitableInteriorwall.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_HabitableInteriorwall']").prop("checked", true);
                        });
                    }
                    $("#T_HabitableInteriorwallOther").val(data.T_HabitableInteriorwallOther);    //居室装修选择说明内墙其它
                    if (data.T_HabitableCeiling != "" && data.T_HabitableCeiling != null) {
                        $(data.T_HabitableCeiling.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_HabitableCeiling']").prop("checked", true);
                        });
                    }
                    $("#T_HabitableCeilingOther").val(data.T_HabitableCeilingOther);         //居室装修选择说明顶棚其它
                    if (data.T_HabitableGround != "" && data.T_HabitableGround != null) {
                        $(data.T_HabitableGround.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_HabitableGround']").prop("checked", true);
                        });
                    }
                    $("#T_HabitableGroundOther").val(data.T_HabitableGroundOther);          //居室装修选择说明地面其它
                    $("#T_ToiletID").val(data.T_ToiletID);                      //卫生间装修情况编号（字典）
                    if (data.T_ToiletInteriorwall != "" && data.T_ToiletInteriorwall != null) {
                        $(data.T_ToiletInteriorwall.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_ToiletInteriorwall']").prop("checked", true);
                        });
                    }
                    $("#T_ToiletInteriorwallOther").val(data.T_ToiletInteriorwallOther);       //卫生间装修选择说明内墙其它
                    if (data.T_ToiletCeiling != "" && data.T_ToiletCeiling != null) {
                        $(data.T_ToiletCeiling.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_ToiletCeiling']").prop("checked", true);
                        });
                    }
                    $("#T_ToiletCeilingOther").val(data.T_ToiletCeilingOther);            //卫生间装修选择说明顶棚其它
                    if (data.T_ToiletGround != "" && data.T_ToiletGround != null) {
                        $(data.T_ToiletGround.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_ToiletGround']").prop("checked", true);
                        });
                    }
                    $("#T_ToiletGroundOther").val(data.T_ToiletGroundOther);             //卫生间装修选择说明地面其它
                    $("#T_KitchenID").val(data.T_KitchenID);                     //厨房装修情况编号 （字典）
                    if (data.T_KitchenInteriorwall != "" && data.T_KitchenInteriorwall != null) {
                        $(data.T_KitchenInteriorwall.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_KitchenInteriorwall']").prop("checked", true);
                        });
                    }
                    $("#T_KitchenInteriorwallOther").val(data.T_KitchenInteriorwallOther);      //厨房装修选择说明内墙其它
                    if (data.T_KitchenCeiling != "" && data.T_KitchenCeiling != null) {
                        $(data.T_KitchenCeiling.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_KitchenCeiling']").prop("checked", true);
                        });
                    }
                    $("#T_KitchenCeilingOther").val(data.T_KitchenCeilingOther);           //厨房装修选择说明顶棚其它
                    if (data.T_KitchenGround != "" && data.T_KitchenGround != null) {
                        $(data.T_KitchenGround.split(",")).each(function (i, dom) {
                            $(":checkbox[value='" + dom + "'][name='T_KitchenGround']").prop("checked", true);
                        });
                    }
                    $("#T_KitchenGroundOther").val(data.T_KitchenGroundOther);            //厨房装修选择说明地面其它
                    $("#T_Explain").val(data.T_Explain);                                  //有关说明
                }
            }
        }
    })


})